package com.ecommerce.auth.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber, String> {

    @Override
    public boolean isValid(String phoneNumber, ConstraintValidatorContext context) {
        // 如果为null或空字符串，则跳过验证
        if (phoneNumber == null || phoneNumber.trim().isEmpty()) {
            return true;
        }
        
        // 验证手机号格式
        return phoneNumber.matches("^1[3-9]\\d{9}$");
    }
}